docke需要修改资源管理驱动为systemd,不然会报下面的问题,当然这个也可以写到剧本里 err="failed to run Kubelet: misconfiguration: kubelet cgroup driver: \"systemd\" is different from docker cgroup driver: \"cgroupfs\""
1 2 3 4
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible all -m shell -a "sed -i '3i ,\"exec-opts\": [\"native.cgroupdriver=systemd\"]' /etc/docker/daemon.json" -i node-host
192.168.26.155 | CHANGED | rc=0 >>
restart docke,当然也可以 reload 之后 start
1 2 3
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible all -m shell -a 'systemctl restart docker' -i node-host 192.168.26.155 | CHANGED | rc=0 >>
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible all -m shell -a 'kubeadm join 192.168.26.81:6443 --token vmya1o.xprnhn8ub6wzzb2e --discovery-token-ca-cert-hash sha256:2e17952177d9c633254e6941849885fc8e0e16dde805425effa22ed04415e7d4' -i node-host
192.168.26.155 | CHANGED | rc=0 >> [preflight] Running pre-flight checks [preflight] Reading configuration from the cluster... [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml' [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Starting the kubelet [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster. [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service' [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
根据提示,处理下警告
1 2 3 4 5 6 7
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible all -m shell -a 'systemctl enable docker.service --now;systemctl enable kubelet.service --now' -i node-host 192.168.26.155 | CHANGED | rc=0 >> Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service. ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$
master 查看节点状态,vms155.liruilongs.github.io Ready
1 2 3 4 5 6 7 8 9 10
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME vms155.liruilongs.github.io Ready <none> 7m19s v1.22.2 192.168.26.155 <none> CentOS Linux 7 (Core) 3.10.0-693.el7.x86_64 docker://20.10.21 vms156.liruilongs.github.io Ready <none> 66m v1.22.2 192.168.26.156 <none> CentOS Linux 7 (Core) 3.10.0-693.el7.x86_64 docker://20.10.21 vms81.liruilongs.github.io Ready control-plane,master 324d v1.22.2 192.168.26.81 <none> CentOS Linux 7 (Core) 3.10.0-1160.76.1.el7.x86_64 docker://20.10.9 vms82.liruilongs.github.io Ready <none> 324d v1.22.2 192.168.26.82 <none> CentOS Linux 7 (Core) 3.10.0-693.el7.x86_64 docker://20.10.9 vms83.liruilongs.github.io Ready <none> 324d v1.22.2 192.168.26.83 <none> CentOS Linux 7 (Core) 3.10.0-693.el7.x86_64 docker://20.10.9 ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$